package com.gitee.pagekit.utils;

import java.lang.reflect.Field;

/**
 * @author wxy
 * @version 1.0
 * @date 2024/5/11 17:29
 */
public class ReflexUtil {

    public static <T> boolean setByFieldName(Class<T> clazz, T t, String fieldName, Object o) throws Exception{
        final Field field = clazz.getDeclaredField(fieldName);
        field.setAccessible(true);
        field.set(t, o);
        return true;
    }

    public static <T> Object getByFieldName(Class<?> clazz, T t, String fieldName) throws Exception{
        final Field field = clazz.getDeclaredField(fieldName);
        field.setAccessible(true);
        return field.get(t);
    }
}
